import {fetchRequest} from '../../utils/request';

export function getUserInfo(){ /*绑定用户*/
	console.log('getUserInfo 1')
	wx.login({
	  success(res) {
		let data = {code:res.code}
		fetchRequest('/h5app/oauth',data,'post').then(json=>{
			wx.setStorageSync('userInfo', json.data.d)
		})
	  }
	})
}
export function debounce(fn, delay){ /*函数防抖*/
  var timer = null; // 声明计时器
  return function() {
    var context = this;
    var args = arguments;
    clearTimeout(timer);
    timer = setTimeout(function () {
      fn.apply(context, args);
    }, delay || 300);
  };
}
export function  throttle(fn, interval) {/*函数节流*/
  var enterTime = 0;//触发的时间
  var gapTime = interval || 300 ;//间隔时间，如果interval不传，则默认300ms
  return function() {
    var context = this;
    var backTime = new Date();//第一次函数return即触发的时间
    if (backTime - enterTime > gapTime) {
      fn.call(context,arguments);
      enterTime = backTime;//赋值给第一次触发的时间，这样就保存了第二次触发的时间
    }
  };
}
export const commonAPI = {	
  //首页接口
   tabData:(data)=>{
	 return fetchRequest('/h5app/index/tabdata',data,'post')
   },
   modsort:(data)=>{
   	 return fetchRequest('/h5app/index/modsort',data,'post')
   },
   getmusicvideo:(data)=>{
   	 return fetchRequest('/h5app/index/getmusicvideo',data,'post')
   },
   guessdata:(data)=>{
   	 return fetchRequest('/h5app/index/guessdata',data,'post')
   },
   getlive:(data)=>{
   	 return fetchRequest('/h5app/index/getlive',data,'post')
   },
   getad:(data)=>{
   	 return fetchRequest('/h5app/index/getad',data,'post')
   },
   liveData:(data)=>{
   	 return fetchRequest('/h5app/index/channel-live-data',data,'post')
   },
   check:(data)=>{
   	 return fetchRequest('/h5app/live/check-status',data,'post')
   },
  //当地首页 
  localData:(data)=>{
  	 return fetchRequest('/h5app/index/local-index',data,'post')
  },
  getMusiclocal:(data)=>{
  	 return fetchRequest('/h5app/index/getmusicvideolocal',data,'post')
  },
  
  
  // 直播发消息
  sendMsg:(data)=>{
   return fetchRequest('/h5/channel/chat/send-comment',data,'post')
  },
  // 直播发@消息
  sendatMsg:(data)=>{
   return fetchRequest('/h5/channel/user/show-at-comment',data,'post')
  },
  // 关注
  follow:(data)=>{
   return fetchRequest('/h5app/user/follow-v2',data,'post')
  },
  // 关注频率
  followChannel:(data)=>{
    return fetchRequest('/h5app/index/follow-channel',data,'post')
   },
  
  //直播间短视频列表
  videoList:(data)=>{
    return fetchRequest('/h5app/live/video',data,'post')
   },
  
}